package org.zjt.book

/**
  * case class ：
  *   自动实现copy tostring hashcode apply unapply等方法
  */
//抽象类Person
abstract class Persons
//case class Student
case class Student( var name:String,  var age:Int,var studentNo:Int) extends Persons
//case class Teacher
case class Teacher( var name:String, var age:Int,teacherNo:Int) extends Persons
//case class Nobody
case class Nobody( var name:String) extends Persons

object CaseClassDemo{


  def main(args: Array[String]): Unit = {
    //case class 会自动生成apply方法，从而省去new操作
    val p:Persons=Student("john",18,1024)


    //match case 匹配语法
    p  match {

        //unapply()方法调用
      case Student(name,age,studentNo)=>println(name+":"+age+":"+studentNo)
      case Teacher(name,age,teacherNo)=>println(name+":"+age+":"+teacherNo)
      case Nobody(name)=>println(name)
    }
  }


}
